package com.nearbymap.model;

public class LatLng {
	private double lat;
	private double lng;
	public LatLng(double lat, double lng) {
		this.lat = lat;
		this.lng = lng;
	}
	public LatLng calcMidPoint(LatLng that) {
		return new LatLng((this.lat + that.lat)/2,(this.lng + that.lng)/2);
	}
	public double calcDistance(LatLng that) {
	    double earthRadius = 3958.75;
	    double dLat = Math.toRadians(that.lat-this.lat);
	    double dLng = Math.toRadians(that.lng-this.lng);
	    double sindLat = Math.sin(dLat / 2);
	    double sindLng = Math.sin(dLng / 2);
	    double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2)
	            * Math.cos(Math.toRadians(this.lat)) * Math.cos(Math.toRadians(that.lat));
	    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
	    double dist = earthRadius * c;
	    return dist;
	}
	public double getLat() {
		return lat;
	}
	public void setLat(double lat) {
		this.lat = lat;
	}
	public double getLng() {
		return lng;
	}
	public void setLng(double lng) {
		this.lng = lng;
	}
	@Override
	public String toString() {
		return lat + "," + lng;
	}
}
